<?php
//模型
class CourseCollectionModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'course_collection';
	}
	//分页列表
	function get_list($arr=array(),$page=1,$size=10){
		$where = " where 1 ";
		if(isset($arr['user_id'])){
			$where .= " and c.user_id='{$arr['user_id']}' ";
		}
		$sql  = "select c.cid as id,m.name,m.title,m.type_id,m.theme_img,m.duration from 
				".$this->db->dbprefix.$this->table." as c left join 
				".$this->db->dbprefix."course as m on c.cid=m.id 
				
				{$where} LIMIT ".($page-1)*$size .",{$size}";
				
		//var_dump($sql);exit;
		$query = $this->db->query($sql);
		$res = $query->result_array();		
		
		foreach($res as $k=>$v){
			if($v['type_id']==0){
				$res[$k]['type_name'] = '团课';
			}else{
				$res[$k]['type_name'] = '私课';
			}
		}		
		
		$sql  = "select count(*) as num from ".$this->db->dbprefix.$this->table." as c  ".$where;
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return array('list'=>$res,'count' =>$row['num']);		
	}
	//全部列表
	function get_lists(){		
		$sql  = "select * from ".$this->db->dbprefix.$this->table;
		$query = $this->db->query($sql);
		$res = $query->result_array();
		return $res;		
	}
	//详情
	function get_info($user_id,$cid){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where cid='{$cid}' and user_id='{$user_id}' ";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return $row;
	}
	//唯一条件获取详情
	function unique_get_info($field,$value){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where {$field}='{$value}' ";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return $row;
	}
	

}

